package com.ruoyi.web.controller.system;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import com.deepoove.poi.data.*;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.ruoyi.system.domain.Task;
import com.ruoyi.system.domain.waterLevel;
import com.ruoyi.system.mapper.TaskMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * @Auther lql
 * @Date 2024/7/15
 */


public class word {

    public static void render(Map<String, Object> map){
        XWPFTemplate template = XWPFTemplate.compile("E:\\home\\ldshuiweiji.docx").render(map);
        try {
            FileOutputStream out = new FileOutputStream("E:\\home\\out.docx");
            template.write(out);
            out.flush();
            out.close();
            template.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws IOException {
        Map<String, Object> map = new HashMap<>();

        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
        // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
        Configure configure = Configure.builder().bind("ww", policy).build();
        List<waterLevel> forms = new ArrayList<>();
//        forms.add(new waterLevel(1, new BigDecimal(1.0),new BigDecimal(1.0),new BigDecimal(1.0),new BigDecimal(1.0),new BigDecimal(1.0),new BigDecimal(1.0),new BigDecimal(1.0) ));

        map.put("ww",forms);


        File file = new File("E:\\home\\ldshuiweiji.docx");
        XWPFTemplate template = XWPFTemplate.compile(file,configure).render(map);

        FileOutputStream out = new FileOutputStream(new File("E:\\home\\swj.docx"));
        template.write(out);
        out.flush();
        out.close();
        template.close();



    }

}

